package com.yh.spring.struts.controller;



import java.util.HashMap;
import java.util.Map;

import org.apache.struts2.ServletActionContext;
import org.springframework.beans.factory.annotation.Autowired;

import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
import com.yh.spring.mybatis.model.Page;
import com.yh.spring.mybatis.model.Product;
import com.yh.spring.mybatis.service.IProductService;





public class ProductAction extends ActionSupport implements ModelDriven<Object>{
	private static final long serialVersionUID = 1L;
	
	
	@Autowired
	private IProductService productService;
	
	
	private Product product;
	private int pageSize;//每页大小
	private int surrentPage;//当前页码
	private Page page;
	
	

	public Product getProduct() {
		return product;
	}

	public void setProduct(Product product) {
		this.product = product;
	}

	public int getPageSize() {
		return pageSize;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	public int getSurrentPage() {
		return surrentPage;
	}

	public void setSurrentPage(int surrentPage) {
		this.surrentPage = surrentPage;
	}

	public Page getPage() {
		return page;
	}

	public void setPage(Page page) {
		this.page = page;
	}

	/*
	 * 查询单条商品记录
	 *
	 */
	public String findproduct(){
		product=productService.getProduct(product);
		ServletActionContext.getRequest().setAttribute("data",product);
		return "success";

	}
	
	
	public String insertProduct() {
		// TODO Auto-generated method stub
		productService.insertProduct(product);
		return "success";
	}

	
	public String deleteProduct() {
		// TODO Auto-generated method stub
		productService.deleteProduct(product);
		return "success";
	}

	
	public String updateProduct( ) {
		productService.updateProduct(product);
		return "success";
	}
	              
	public String queryLikeProduct(){
		Map<String,Object> cond=new HashMap<String,Object>();
		cond.put("pageSize", pageSize);
		cond.put("surrentPage", surrentPage);
		cond.put("product", product);
		page=productService.queryLikeProduct(cond);
		return "success";	
	}

	@Override
	public Object getModel() {
		if(product==null){
			product=new Product();
		}
		return product;
	}
	
}
   